package com.zxy.main;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@WebListener
public class WebSocketServletListener implements ServletRequestListener
{
	@Override
	public void requestDestroyed(ServletRequestEvent sre)
	{
	}

	@Override
	public void requestInitialized(ServletRequestEvent sre)
	{
		HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
		HttpSession session = request.getSession();
		session.setAttribute("WebSocketClientIP",sre.getServletRequest().getRemoteAddr()
				+ ":" + sre.getServletRequest().getRemotePort());
		// 把HttpServletRequest中的IP:Port地址放入HttpSession中，关键字可任取，此处为WebSocketClientIP
	}
}
